﻿<%@ Page Title="Enrollment" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Enrollment.aspx.cs" Inherits="Testify.Enrollment" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <asp:SqlDataSource ID="sqlStudents" runat="server"
        ConnectionString="<%$ ConnectionStrings:Singularity %>"
        ProviderName="<%$ ConnectionStrings:Singularity.ProviderName %>"
        SelectCommand="SELECT user_id AS student_id, user_last_name || ', ' || user_first_name AS studentName 
                         FROM testify_user WHERE user_type_id = 3 
                          AND user_maint NOT LIKE 'D' 
                        ORDER BY user_last_name, user_first_name">
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="sqlClasses" runat="server"
        ConnectionString="<%$ ConnectionStrings:Singularity %>"
        ProviderName="<%$ ConnectionStrings:Singularity.ProviderName %>" 
        SelectCommand="SELECT section_id, course_type_prefix || ' ' || course_number || '-' || section_number || ': ' || course_name AS course_fancy, term_type_name || ' ' || term_year AS term
                           FROM singularity.section s
                           JOIN singularity.class  cls USING (class_id)
                           JOIN singularity.term trm USING (term_id)
                           JOIN singularity.term_type USING (term_type_id)
                           JOIN singularity.course crs USING (course_id)
                           JOIN singularity.course_type crst USING (course_type_id)
                          WHERE term_id = :term
                            AND 'D' NOT IN (section_maint, term_maint, /*term_type_maint,*/ course_maint, course_type_maint, term_maint)
                          ORDER BY trm.term_start_date, course_type_prefix, course_number, section_number" >
       <SelectParameters>
          <asp:ControlParameter ControlID="ddlTerm" DefaultValue="-1" Name="term" 
             PropertyName="SelectedValue" />
       </SelectParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="sqlTerm" runat="server"
        ConnectionString="<%$ ConnectionStrings:Singularity %>"
        ProviderName="<%$ ConnectionStrings:Singularity.ProviderName %>" 
        SelectCommand="SELECT -1 as term_id, 'Select a Term' as termName from dual
                        UNION SELECT term_id, term_type_name || ' ' || term_year as termName 
                         FROM term
                         JOIN term_type USING (term_type_id)
                        WHERE term_end_date &gt; sysdate
                          AND term_start_date &lt; add_months(sysdate, 6)
                          AND term_maint NOT LIKE 'D'" >
    </asp:SqlDataSource>

   <asp:SqlDataSource ID="sqlViewEnroll" runat="server"
           ConnectionString="<%$ ConnectionStrings:Singularity %>"
           ProviderName="<%$ ConnectionStrings:Singularity.ProviderName %>" 
           SelectCommand="SELECT user_last_name as LastName, user_first_name AS FirstName, enrollment.rowid as p_rowID
                            FROM testify_user
                            JOIN enrollment on student_id = user_id
                           WHERE section_id = :section_id
                             AND user_maint NOT LIKE 'D'"
           DeleteCommand="ENROLLMENTS.deleteEnrollment"
           DeleteCommandType="StoredProcedure">

         <SelectParameters>
            <asp:ControlParameter ControlID="ddlClasses" DefaultValue="-1" 
               Name="section_id" PropertyName="SelectedValue" />
         </SelectParameters>

         <DeleteParameters>
            <asp:ControlParameter ControlID="gdvViewEnroll" Name="p_rowID" 
               PropertyName="SelectedValue" />
         </DeleteParameters>

       </asp:SqlDataSource>

    <table id="enroll_table">
        <tr align="left">
           <asp:Label ID="lblInfoMsg" SkinID="InfoMessage" runat="server" />
           <asp:Label ID="lblErrorMsg" SkinID="ErrorMessage" runat="server" />
        </tr><tr>
            <td>
               <asp:LinkButton ID="lbtAddEnroll" class="btn_details btn_enroll" runat="server" Text="Enroll New Students" OnClick="showAddEnroll_Click" />
               <asp:LinkButton ID="lbtViewEnroll" class="btn_details btn_enroll" runat="server" Text="View Enrolled Students" OnClick="changeDisplay_Click" Visible="false" />
            </td>
        </tr><tr>
           <%--<asp:UpdatePanel ID="udatepanel1" runat="server" >
              <ContentTemplate>--%>
              <td>
                 <asp:DropDownList ID="ddlTerm" runat="server" DataSourceID="sqlTerm" 
                    DataTextField='termName' DataValueField='term_id' 
                    Font-Names="Courier New" AutoPostBack="true" />

                 <asp:DropDownList ID="ddlClasses" runat="server" DataSourceID="sqlClasses" 
                    DataTextField='course_fancy' DataValueField='section_id' 
                    Font-Names="Courier New" AutoPostBack="true" AppendDataBoundItems="true" 
                      OnDataBinding="clearDropDown" 
                      onselectedindexchanged="ddlClasses_SelectedIndexChanged" 
                      ondatabound="ddlClasses_DataBound" />
              </td>
           <%--   </ContentTemplate>
           </asp:UpdatePanel>--%>
        </tr><tr>
            <td align="center">
               <asp:Panel ID="pnlViewEnroll" runat="server" >
                  <asp:GridView ID="gdvViewEnroll" runat="server" DataSourceID="sqlViewEnroll" AutoGenerateColumns="false" DataKeyNames="p_rowID"
                     AllowSorting="true" >
                     <Columns>
                        <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" ItemStyle-HorizontalAlign="Left" />
                        <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" ItemStyle-HorizontalAlign="Left" />
                        <asp:TemplateField>
                           <ItemTemplate>
                              <asp:ImageButton ID="btnRemoveStudent" SkinID="deleteButton" runat="server" ToolTip="Remove from class" CommandName="Delete" />
                              <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" DisplayModalPopupID="customConfirm"
                                  TargetControlID="btnRemoveStudent" />
                              <asp:ModalPopupExtender ID="customConfirm" runat="server"
                                TargetControlID="btnRemoveStudent" PopupControlID="custom_panel" 
                                OkControlID="btn_ok" CancelControlID="btn_cancel"
                                BackgroundCssClass="modalBackground" >
                              </asp:ModalPopupExtender>
                              <asp:Panel ID="custom_panel" runat="server" CssClass="modalDialog">
                                <div class="modalBackground">
                                    Are you sure you want <br />to remove this student?
                                    <br /><br />
                                    <asp:Button ID="btn_ok" class="modalButton" runat="server" Text="Yes" />
                                    <asp:Button ID="btn_cancel" class="modalButton" runat="server" Text="No" />
                                </div>
                              </asp:Panel>
                           </ItemTemplate>
                        </asp:TemplateField>
                     </Columns>
                  </asp:GridView>
               </asp:Panel>

                <asp:Panel ID="pnlEnroll" runat="server" Visible="false">
                   <asp:Button ID="btnEnrollStudentsTop" CssClass="btn_details btn_enroll btn_enrollActual" runat="server" Text="Enroll Students" onclick="btnEnrollStudents_Click" />
                   <asp:GridView ID="gdvStudents" runat="server" AutoGenerateColumns="false" DataSourceID="sqlStudents">
                      <Columns>
                         <asp:TemplateField ShowHeader="false">
                            <HeaderTemplate>
                               <asp:Button ID="btnShowInsert" runat="server" OnClick="btnShowInsert_onClick" Text="Add" Visible="false" />
                               <asp:Label ID="Label5" runat="server" Text="Check to add" />
                            </HeaderTemplate>
                            <ItemStyle HorizontalAlign="center" Width="60px" />
                            <ItemTemplate>
                               <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" Visible="false" />
                               <asp:LinkButton ID="lnkDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Remone" Visible="false" />
                               <asp:CheckBox ID="chkAdd" runat="server" CausesValidation="False" Checked="false" Visible="true" />
                               <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" 
                                  ConfirmText="Are you sure you want to remove this student?" TargetControlID="lnkDelete" />
                            </ItemTemplate>
                            <EditItemTemplate>
                               <asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="False" CommandName="Update" Text="Update" />
                               <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                            </EditItemTemplate>
                         </asp:TemplateField>
                         <asp:TemplateField headertext="ID" SortExpression="student_id">
                            <ItemStyle Wrap="false" />
                            <ItemTemplate>
                               <asp:Label ID="lblStudentID" runat="server" Text='<%# Eval("student_id") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                               <asp:TextBox ID="lblID" runat="server" Text='<%# Eval("student_id") %>' />
                            </EditItemTemplate>
                         </asp:TemplateField>
                         <asp:TemplateField headertext="Student Name" SortExpression="StudentName">
                            <ItemStyle Wrap="false" />
                            <ItemTemplate>
                               <asp:Label ID="lblStudentName" runat="server" 
                                  Text='<%# Eval("StudentName") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                               <asp:Label ID="lblName" runat="server" Text='<%# Eval("StudentName") %>' />
                            </EditItemTemplate>
                         </asp:TemplateField>
                      </Columns>
                   </asp:GridView>
                   <asp:Button ID="btnEnrollStudentsBottom" CssClass="btn_details btn_enroll btn_enrollActual" runat="server" Text="Enroll Students" onclick="btnEnrollStudents_Click" />
               </asp:Panel>
           </td>
        </tr>
    </table>

</asp:Content>

